package com.itheima.health.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.mapper.PermissionMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {


    @Override
    public Result findPage(QueryPageBean queryPageBean) {
        Page<Permission> page=null;
        QueryWrapper<Permission> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete",0);
        if (StringUtils.isBlank(queryPageBean.getQueryString())) {
             page = page(new Page<Permission>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),wrapper);
        }else {
            wrapper.like("name",queryPageBean.getQueryString());
            page = page(new Page<Permission>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),wrapper);
        }
        PageResult pageResult = new PageResult(page.getTotal(), page.getRecords());
        Result result = new Result();
      result.setData(pageResult);
        return result;
    }

    @Override
    public Boolean add(Permission permission) {
        boolean flag = this.saveOrUpdate(permission);

        return flag;
    }

    @Override
    public Boolean deleteCheckItemById(int id) {
        Permission permission = new Permission();
        permission.setId(id);
        permission.setIs_delete(1);
        boolean flag = updateById(permission);
        return flag;
    }
}
